package cjq.demo.thread.ch4_9;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/4/30.
 */
public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();

        Task task = new Task();

        System.out.println("Main : Executing the Task ");
        Future<String> result = executor.submit(task);

        try{
            TimeUnit.SECONDS.sleep(2);
        }catch(InterruptedException e){
            e.printStackTrace();
        }

        System.out.println("Main: Canceling the Task");
        result.cancel(true);

        System.out.println("Main : Cancelled :"+result.isCancelled());
        System.out.println("Main: Done : "+ result.isDone());

        executor.shutdown();

        System.out.println("Main : The executor has finished ");

    }
}
